(require (planet schematics/schemeunit:3))

(define (square x) (* x x))

(define (cbrt-iter guess x)
  (if (good-enough? guess x)
      guess
      (cbrt-iter (improve guess x)
                 x)))

(define (improve guess x)
  (/ (+ (/ x (square guess)) guess guess) 3))

(define (good-enough? guess x)
  (<
   (abs (- 1.0 (/ (improve guess x) guess)))
   1e-5))

(define (cbrt x)
  (cbrt-iter 1.0 x))

(define (cbrt x)
  (cbrt-iter 1.0 x))


(check-= (cbrt 27) 3 0.0001)
(check-= (cbrt 8) 2 0.0001)
(check-= (cbrt 1e90) 1e30 1e25)
(check-= (cbrt 1e-90) 1e-30 1e-25)
